import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue';
import './assets/global.less';
import components from './components/global';
import Router from './router/index';
import { useAuthStore } from './stores/authStore';

const app = createApp(App)
const pinia = createPinia()

// components
for (const i in components) {
  app.component(i, components[i])
}

app.use(pinia).use(Router)

// Electron环境检测和初始化
if (window.electronAPI) {
  console.log('运行在Electron环境中');
  
  // 监听菜单事件
  window.electronAPI.onMenuNewTask(() => {
    // 触发新建任务事件
    window.dispatchEvent(new CustomEvent('electron-new-task'));
  });
  
  window.electronAPI.onMenuSettings(() => {
    // 导航到设置页面
    Router.push('/settings');
  });
  
  window.electronAPI.onMenuAbout(() => {
    // 显示关于信息
    window.dispatchEvent(new CustomEvent('electron-about'));
  });
  
  // 请求通知权限
  window.electronAPI.requestNotificationPermission();
}

// 初始化认证状态
const authStore = useAuthStore()
authStore.initAuth().then(() => {
  app.mount('#app')
}).catch((error) => {
  console.error('认证初始化失败:', error)
  app.mount('#app')
})
